import "../../css/help.css";
import Menu from "@ui/RJMart/menu";
function HelpMenu(props) {

    //初始化插件入参
    const {} = props;
    const orgId = Uts.getCookie("orgId");
    const suppId = Uts.getCookie("suppId");

    //初始化插件状态值及状态更新方法
    const [helpMenuStatus, updatehelpMenuStatus] = React.useState({
        selectedKey:StateApi.getStoreState("commonHeaderConfig").helpCenter
    })

    //更新视图数据 私有的方法前缀用_
    function _updateData(value) {
        let newValue = { ...helpMenuStatus, ...value };
        console.log(newValue);
        updatehelpMenuStatus(newValue);
    }

    //更新选中菜单外部接口
    function updateMenuFunctions(newKey){
        _updateData(
            (helpMenuStatus.selectedKey = newKey)
        )
    }

    //切换帮助中心菜单
    function selectNewKey(e){
        console.log("selectNewKey",e);
        updateMenuFunctions(e.target.value);
        if(e.target.value == "1"){
            $state.go({
                stateName: "/HelpCenter"
            });
        }else if(e.target.value == "2"){
            $state.go({
                stateName: "/HelpProblems",
                params: {
                    columnId: 0,
                    articleId:0,
                    targetType:0,
                    publishTime:0
                }
            });
        }else if(e.target.value == "3"){
            //window.open(localStorage.getItem("vedioUrl"));
            $state.go({
                stateName: "/HelpVideo"
            });
        }
    }

    //校验当前选中菜单是否需要更新
    function checkSelected(){
        if(StateApi.getStoreState("commonHeaderConfig").helpCenter!=helpMenuStatus.selectedKey){
            console.log("HelpMenuCheck",StateApi.getStoreState("commonHeaderConfig").helpCenter,helpMenuStatus.selectedKey);
            updateMenuFunctions(StateApi.getStoreState("commonHeaderConfig").helpCenter);
        }
    }

    //componentOnMount
    React.useEffect(() => {
        console.log("HelpMenu",$state.params);
        console.log(helpMenuStatus);
    });

    checkSelected();

    return (
        <div className="zen_t-c zen_center" style={{width:"1200px"}}>
            {console.log("renderHelpMenu",helpMenuStatus.selectedKey)}
            {orgId==""&&suppId==""?(
                <Menu style={{"textAlign":"center"}} mode={"inline"} size={"large"} onSelectChange={e => {selectNewKey(e)}} selectedKey={helpMenuStatus.selectedKey} defaultSelectedKey={helpMenuStatus.selectedKey}>
                    <Menu.Item style={{width:"49%",backgroundColor:"#FFFFFF"}} id={"1"}>首页</Menu.Item>
                    <Menu.Item style={{width:"49%",backgroundColor:"#FFFFFF"}} id={"2"}>常见问题</Menu.Item>
                </Menu>
                ):(
                    <Menu style={{"textAlign":"center"}} mode={"inline"} size={"large"} onSelectChange={e => {selectNewKey(e)}} selectedKey={helpMenuStatus.selectedKey} defaultSelectedKey={helpMenuStatus.selectedKey}>
                        <Menu.Item style={{width:"33%",backgroundColor:"#FFFFFF"}} id={"1"}>首页</Menu.Item>
                        <Menu.Item style={{width:"33%",backgroundColor:"#FFFFFF"}} id={"2"}>常见问题</Menu.Item>
                        <Menu.Item style={{width:"33%",backgroundColor:"#FFFFFF"}}id={"3"}>视频教程</Menu.Item>
                    </Menu>
                )
            }
        </div>
    )
}

export default HelpMenu;